package service;

import bean.Customer;

public class CustomerList {
    private Customer[] customers;//保存客户对象的数组
    private int total=0;//记录已保存客户的数量；
    /** 
     * @description: 用来初始化customer数组的构造器
     * @param: totalCustomer:指定数组的长度
     * @return: 
     * @author Admin
     * @date: 2021/3/27 16:18
     */ 
    public CustomerList(int totalCustomer){
        customers=new Customer[totalCustomer];

    }
    /** 
     * @description: 将指定客户添加到数组中
     * @param: customer
     * @return: boolean true:添加成功 false:添加失败
     * @author Admin
     * @date: 2021/3/27 16:22
     */ 
    public boolean addCustomer(Customer customer){
        if (total>=customers.length){
            return false;
        }
        customers[total++]=customer;
        return true;
    }
    /** 
     * @description: 修改指定索引位置的客户信息
     * @param: index：索引
cust：客户信息
     * @return: boolean true:修改成功 false:修改失败
     * @author Admin
     * @date: 2021/3/27 16:32
     */ 
    public boolean replaceCustomer(int index, Customer cust){
        if (0>index||index>total){
            return false;
        }
        customers[index]=cust;
        return true;
    }
    /**
     * @description: 删除指定索引的客户信息
     * @param: index ：指定索引
     * @return: boolean true:删除成功 false:删除失败
     * @author Admin
     * @date: 2021/3/27 16:39
     */
    public boolean deleteCustomer(int index){
        if (0>index||index>total){
            return false;
        }
        for (int i=index;i<total-1;i++){
            customers[i]=customers[i+1];
        }
        customers[total--]=null;
        return true;
    }
    /**
     * @description: 获取所有的客户信息
     * @param:
     * @return: com.lei.p2.bean.Customer[]
     * @author Admin
     * @date: 2021/3/27 16:51
     */
    public Customer[] getAllCustomers(){
        Customer[]custs=new Customer[total];
        for (int i=0;i<total;i++){
            custs[i]=customers[i];
        }
        return custs;


    }
    /**
     * @description: 获取指定索引的客户信息
     * @param: index
     * @return: com.lei.p2.bean.Customer
     * @author Admin
     * @date: 2021/3/27 17:00
     */
    public Customer getCustomer(int index){
        if (0>index||index>total){
            return  null;
        }
        return customers[index];

    }
    /**
     * @description: 获取存储的客户数量
     * @param:
     * @return: int
     * @author Admin
     * @date: 2021/3/27 17:02
     */
    public int getTotal(){
        return total;

    }


}
